import { log } from "cc"

import { create } from "@bufbuild/protobuf"
import { RoomSchema } from "sgc"
import { cat } from "@shimotsuki/core"

/**查询房间 */
export async function QueryAliveRoom() {
    try {
        // 获取房间状态
        cat.gui.showLoading({ title: '获取数据' })
        const res = await cat.room_ws.QueryAliveRoom()
        log('QueryAliveRoom', res)
        if (res.room) {
            cat.store.room.roomInfo = res.room
        } else {
            cat.store.room.roomInfo = create(RoomSchema)
        }
    } catch (error) {
        cat.store.room.roomInfo = create(RoomSchema)
    }
    cat.gui.hideLoading()

}